// pages/agent/index.js
const { allJj } =  require('../../http/api')
const { dayJj } =  require('../../http/api')
const { backJj } =  require('../../http/api')
const { profiles } =  require('../../http/api')
const { agentList } =  require('../../http/api')
const {
  baseUrl
} = require('../../http/env').prod
Page({

  /**
   * 页面的初始数据
   */
  data: {
    all:'', //全部
    reject:'', //驳回
    today:'', //今日
    junior:'', //下级
    avatar:'', //头像
    names:'', 
    fx_code:'', //邀请码
    id:'', //代理商ID
  },
  //全部进件
  getAllJj(){
    allJj().then(res=>{
      this.setData({
        all:res.data.length
      })
    })
  },
  //今日进件
  getDayJj(){
    dayJj().then(res=>{
      this.setData({
        today:res.data.length
      })
    })
  },
  //驳回进件
  getBackJj(){
    backJj().then(res=>{
      this.setData({
        reject:res.data.length
      })
    })
  },
  //下级代理商列表
  getAgentList(){
    console.log(111)
    var _this = this
    agentList().then(res=>{
      if(res.code == 200){
        _this.setData({
          junior:res.count
        })
      }
    })
  },
  //跳转
  rejectTap(){
    wx.navigateTo({
      url: '../Rejectlist/index',
    })
  },
  allJjTap(){
    wx.navigateTo({
      url: '../allJJ/index',
    })
  },
  dayJjTap(){
    wx.navigateTo({
      url: '../dayJJ/index',
    })
  },
  juniorTap(){
    const id = this.data.id
    wx.navigateTo({
      url: '../junior/index',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      tabsActive:options.tab
    })
    this.getAllJj()
    this.getDayJj()
    this.getBackJj()
    this.getprofiles()
    this.getAgentList()
  },
  getprofiles(){
    profiles().then(res=>{
      this.setData({
        avatar:res.data.avatar,
        names:res.data.nickname,
        fx_code:res.data.fx_code,
        id:res.data.id
      })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getAllJj()
    this.getDayJj()
    this.getBackJj()
    this.getprofiles()
    this.getAgentList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})